﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using EShop.DAL;

namespace EShop.BLL
{
    public class MemberManagerBLL
    {
        MemberManagerDAL oMemberManagerDAL = new MemberManagerDAL();

        /// <summary>
        /// 获取会员
        /// </summary>
        /// <param name="strMemberID"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public DataTable GetMember(string strMemberID, int type)
        {
            return oMemberManagerDAL.GetMember(strMemberID, type);
        }

        public DataTable GetLevelInfo()
        {
            return oMemberManagerDAL.GetLevelInfo();
        }

        public bool MemberInfoAppend(string strMemberID, string strMemberName,
            byte Sex, DateTime Brithday, byte IsGregorianCalendar, int LevelID,
            string MemberMobile, string MemberAddress, string Remark)
        {
            if (oMemberManagerDAL.MemberInfoAppend(strMemberID, strMemberName, Sex, Brithday, IsGregorianCalendar, LevelID, MemberMobile, MemberAddress, Remark) > 0) return true;
            else return false;
        }

        public bool MemberScoreAppend(string MemberID, int MemberScoreValue, byte IsLimitTime, DateTime LasLimitTime)
        {
            return oMemberManagerDAL.MemberScoreAppend(MemberID, MemberScoreValue, IsLimitTime, LasLimitTime) > 0 ? true : false;
        }

        public bool MemberInfoUpdate(string strMemberID, string strMemberName,
            byte Sex, DateTime Brithday, byte IsGregorianCalendar, int LevelID,
            string MemberMobile, string MemberAddress, string Remark)
        {
            if (oMemberManagerDAL.MemberInfoUpdate(strMemberID, strMemberName, Sex, Brithday, IsGregorianCalendar, LevelID, MemberMobile, MemberAddress, Remark) > 0) return true;
            else return false;
        }

        public bool MemberLevelInfoAppend(string LevelName, decimal LevelDiscount)
        {
            return oMemberManagerDAL.MemberLevelInfoAppend(LevelName, LevelDiscount) > 0 ? true : false;
        }

        public bool MemberLevelInfoUpdate(string LevelID, string LevelName, decimal LevelDiscount)
        {
            return oMemberManagerDAL.MemberLevelInfoUpdate(LevelID, LevelName, LevelDiscount) > 0 ? true : false;
        }

        public string GetStatus(int type)
        {
            string tmp = string.Empty;
            switch (type)
            {
                case 0:
                    tmp = "正常";
                    break;
                case 1:
                    tmp = "系统";
                    break;
                case 2:
                    tmp = "停用";
                    break;
                default:
                    tmp = "Unknowable";
                    break;
            }
            return tmp;
        }


        public DataTable GetMemberConsumeHistoryYear(string strMemberID)
        {
            return oMemberManagerDAL.GetMemberConsumeHistoryYear(strMemberID);
        }

        public DataTable GetMemberConsumeHistoryMonth(string strMemberID, string Year)
        {
            return oMemberManagerDAL.GetMemberConsumeHistoryMonth(strMemberID, Year);
        }

        public DataTable GetMemberConsumeHistoryDay(string strMemberID, string Year, string Month)
        {
            return oMemberManagerDAL.GetMemberConsumeHistoryDay(strMemberID, Year, Month);
        }

        public DataTable GetMemberConsumeHistory(string strMemberID, int iType, string strYear, string strMonth, string strDay, out decimal RealAmount)
        {
            DataSet ds=oMemberManagerDAL.GetMemberConsumeHistory(strMemberID, iType, strYear, strMonth, strDay);
            try
            {
                RealAmount = Convert.ToDecimal(ds.Tables[0].Rows[0][0]);
            }
            catch {
                RealAmount = 0;
            }
            return ds.Tables[1];
        }

    }
}
